/**
 * 洞察流程信息存储，对外提供获取流程节点配置参数的方法
 */
var MineFlowInfo = {};
/**
 * 文件输出和缺失值处理节点判断遍历array的标识
 * @type {number}
 */
var count = 0;

/**
 * 流程是否执行成功
 */
var flowIsFailed = true;

/**
 * MLeap模型是否存在
 */
var mLeapModelIsExists = true;

/**
 * 挖掘洞察控制类
 * mode: 空值显示当前执行洞察信息还是成果分类的洞察信息
 * pid: 流程id或者成果id（mode为true）
 * exeId: 执行id
 */
function MineViewlingController(pid, mode, exeId) {
    var mask = null;
    var insightCache = {};
    var nodeTypeClickCache = {};
    if (!mode && window.apiInsight != null) {
        window.updateview = true
    }

    //遮罩
    var showMaskOpt = function (opt) {
        if (opt == 'show') {
            mask = $("<div/>").tempoprogressbar();
        } else {
            if (mask) {
                mask.tempoprogressbar('close');
            }
        }
    }
    // 成果分类展示洞察时，则启用新的url
    var getUrl = function (key, defaultValue) {
        var url = {
            "processInfo": "/api/ai/app/insight/get-process-info",
            "flowView": "/api/ai/app/insight/get-flow-info-object",
            "nodeInsight": "/api/ai/app/insight/list-node-info"
        };
        //判断是否是读取案例库
        if (window.isTemplateState == "true") {
            url = {
                "processInfo": "/api/ai/app/insight/template/get-process-info",
                "flowView": "/api/ai/app/insight/template/get-flow-info",
                "nodeInsight": "/api/ai/app/insight/template/list-node-info"
            };
        }
        //判断是否是版本管理
        if (window.isSnapshotInsight == "true") {
            url = {
                "processInfo": "/api/ai/app/insight/get-process-info",
                "flowView": "/api/ai/mine/getObjectFlowInfoForView",
                "nodeInsight": "/api/ai/app/insight/list-node-info"
            };
        }
        return (mode && url[key]) || defaultValue;
    }

    var bindEvent = function (data) {
        // 流程图点击事件
        $('body').off('click.insight').on('click.insight', nodeInsight);
    }

    /**
     * 流程图点击事件处理
     */
    var nodeInsight = function (event) {
        //如当前模式处于洞察的时候，则可请求加载数据，否则截断
        var analyseStatus = Eventbus.triggerHandler("getAnalyseStatus")[0];
        if ('viewing' != analyseStatus.getType()) {
            return;
        }
        var currentTabName = $(event.target).attr("name");
        if (currentTabName) {
            currentTabName = currentTabName.split("#");
            var nodeConfigId = currentTabName[0];
            var portCode = currentTabName[1];
            nodeTypeClickCache[nodeConfigId] = portCode;
        }
        //如果是流程节点，显示节点洞察
        if (arguments.length > 2 && (arguments[1] == 'miningnode' || arguments[1] == 'subprocess')) {
            if (arguments.length == 4) {
                var tar = arguments[3];
                if (tar.attr("_widgetName") == 'minesubprocessnode') {
                    return;
                }
            }
            var eid = arguments[2];
            loadNodeInsight(eid)
        } else if ($(event.target).hasClass('tempo-mine-board-container') || $(arguments[0].target).hasClass('tempo-mine-board-container') || $(arguments[0].target).hasClass('tempo-board-container')) {
            //如果是空白部分，显示流程综述
            addTab('desc');
        } else if ($(event.target).hasClass('ui-tabs-anchor')) {
            var eid = $(".tempo-basenode-select").attr("id");
            if (eid) {
                loadNodeInsight(eid);
            }
        }
    }

    /**
     * 获取节点洞察数据
     * 添加节点洞察缓存，减少不必要的请求
     */
    var loadNodeInsight = function (nodeid) {
        showMaskOpt('show');
        var show = function (result) {
            if (result && result.length > 0 && isShowSignalInsight(result)) {
                showNodeInsight(result);
            }
            showMaskOpt('hide');
        }
        if (insightCache[nodeid]) {
            var result = insightCache[nodeid];
            show(result);
            return;
        }
        //兼容API服务的serviceid
        $.postForm({
            url: contextPath + getUrl('nodeInsight', "/api/ai/mine/searchInsightNodeInfo"),
            data: {
                nodeId: nodeid,
                pid: pid,
                flowid: window.flowid,
                exeId: exeId,//可传可不传的参数
            },
            success: function (result) {
                if (result && result.success) {
                    result = result.data;
                }
                //更新洞察的显示顺序
                result = updateInsightOrder(result);
                //增加缓存数据
                insightCache[nodeid] = result;
                show(result);
            },
            error: function () {

            }
        });
    }

    /**
     * 更新洞察的显示顺序
     * @param result
     * @returns {[]} newResult 新的洞察result数据
     */
    var updateInsightOrder = function (result) {
        var newResult = [];
        if (result && result.length > 0 && "scalascript" == result[0].nodeConfigId && "dataset" == result[0].portType) {
            //循环行内scala扩展编程洞察需要重新排序，修改49306bug
            //只有当前节点为scala编程节点，并且第一个洞察显示的是输出数据集洞察需要重新排序。
            for (var i = 0; i < result.length; i++) {
                //只有当前洞察为节点洞察，并且它的上一个洞察是数据集洞察时，需要重新排序，将数据集洞察放到节点洞察前
                if (result[i - 1] && result[i - 1].portType == "dataset" && result[i].portType == "node_default") {
                    newResult.splice(i - 1, 0, result[i]);
                } else {
                    newResult.push(result[i]);
                }
            }
        } else if (result && result.length > 0 && "writefilebatch" == result[0].nodeConfigId) {
            //文件输出需要根据端口编号重新排序，修改65044bug
            try {
                result.sort(function (t1, t2) {
                    var idx1 = t1.port.split("out")[1] == "" ? 0 : parseInt(t1.port.split("out")[1]);
                    var idx2 = t2.port.split("out")[1] == "" ? 0 : parseInt(t2.port.split("out")[1]);
                    return idx1 - idx2;
                })
                newResult = result;
            } catch (e) {
                newResult = result;
            }
        } else {
            newResult = result;
        }
        return newResult;
    }

    /**
     * 判断信号模块洞察是否展示
     * @param result 洞察数据
     * @returns {boolean} 是否展示洞察，true为展示，false为不展示
     */
    var isShowSignalInsight = function (result) {
        if (result && result.length > 0) {
            //判断是否为信号模块节点，并且输出端口是否为S端口
            if (result[0].type == window.constant.DATAMINE_SIGNAL &&
                result[0].portType == window.mineConstant.PORT_SIGNAL) {
                var info = JSON.parse(result[0].info);
                //如果信号模块是否展示节点洞察和是否展示信号数据集洞察都为false时直接返回true
                if (info.isShowNodeData || info.isShowSignalData || info.showNodeData || info.showSignalData) {
                    return true;
                }
            } else {
                //不是信号模块的节点直接返回true
                return true;
            }
        } else {
            //没有数据直接返回false
            return false;
        }
    }

    //显示节点洞察
    var showNodeInsight = function (result) {
        //获取节点id和名称
        var label = result[0].nodeLabel;
        var nodeId = result[0].nodeId;
        var nodeConfigId = result[0].nodeConfigId;
        var insightInfo = JSON.parse(result[0].info);
        if (insightInfo.subInsight && insightInfo.subInsight == "off") {
            return;
        }
        //子流程需要双击打开选择节点才能显示
        if (result[0].nodeConfigId == 'subprocess') {
            return;
        }

        if (result[0].nodeConfigId == 'multiply') {
            var parseInsight = JSON.parse(result[0].info);
            if (parseInsight.hasOwnProperty("cycleLabel") && parseInsight.cycleLabel != null) {
                var results = [];
                var cycleLabels = [];
                for (var i = 0; i < result.length; i++) {
                    var idStrs = result[i].id.split("-");
                    var indexId = idStrs[idStrs.length - 1]
                    if (cycleLabels.indexOf(indexId) == -1) {
                        cycleLabels.push(indexId);
                        results.push(result[i]);
                    }
                }
                result = results;
            } else {
                result = [result[0]];
            }
        }

        //文件输出节点修改portLabel
        if (result[0].nodeConfigId == 'writefile') {
            for (var i = 0; i < result.length; i++) {
                result[i].portLabel = "数据集" + (i + 1);
            }
        }

        var groupBy = function (array, callback) {
            var groups = {};
            array.forEach(function (item) {
                var group = callback(item);
                groups[group] = groups[group] || [];
                groups[group].push(item)
            });
            var sortGroups = {};
            Object.keys(groups).sort().forEach(function (key) {
                sortGroups[key] = groups[key];
            });
            return sortGroups;
        };
        var buildHeaderTab = function (headerTab, contentTab, container) {
            var parseInsight = JSON.parse(result[0].info);
            //针对于循环行洞察优化
            if (parseInsight.hasOwnProperty("cycleLabel") && parseInsight.cycleLabel != null) {
                headerTab.css("margin-bottom", "20px");
                //进来说明是循环行，对result进行分组
                var groupsResult = groupBy(result, function (item) {
                    var cycleLabel = JSON.parse(item.info).cycleLabel;
                    return cycleLabel ? TempoMineUtils.decodeHTML(cycleLabel) : cycleLabel;
                });
                var resultKeys = Object.keys(groupsResult);
                var resultKeysMap = resultKeys.map(function (item, i) {
                    return {
                        value: item
                    }
                });
                if (resultKeys.length > 5) {
                    var spanDiv = $("<div style='display: inline-block;width: calc(100% - 60px);'></div>").appendTo(headerTab);
                    var top5 = resultKeys.splice(0, 5);
                    top5.forEach(function (key) {
                        groupsResult[key].forEach(function (o) {
                            showPortView(spanDiv, contentTab, container, o, window.constant.DATANODES.indexOf(o.nodeConfigId) == -1 || o.locType == 'result' || o.portType == "dataset", top5.length);
                        })
                    });

                    //显示筛选按钮
                    var selectBtn = $("<button style='float: right'>筛选</button>").appendTo(headerTab);

                    selectBtn.button({
                        click: function (e) {
                            var dialog = $("<div/>");
                            var grid = $('<table>').addClass('select_loop_value').appendTo(dialog);

                            dialog.dialog({
                                width: 600,
                                height: 450,
                                autoOpen: true,
                                title: "筛选",
                                modal: true,
                                close: function () {
                                    //dialog.dialog("destroy");
                                    dialog.dialog("close");
                                },
                                open: function () {
                                    grid.datagrid({
                                        width: 558,
                                        height: 180,
                                        rowNum: 100000,
                                        //rowList:[5,10,20,30],
                                        //是否分页
                                        //pagination:true,
                                        datatype: "local",
                                        data: resultKeysMap,
                                        multiselect: true,
                                        rownumbers: true,
                                        colNames: ['循环字段取值'],
                                        colModel: [{
                                            name: 'value',
                                            index: 'value',
                                            sortable: false
                                        }],
                                        searchBar: true,
                                        searchBarOptions: {
                                            placeholder: "请输入关键字",
                                            onSearch: function (text) {
                                                var list = this.find("tr[id] td:nth-child(3)");
                                                var ids = grid.datagrid("getRowIds");
                                                for (var i = 0; i < list.length; i++) {
                                                    var node = list[i];
                                                    var data = grid.datagrid("getRowData",ids[i]);
                                                    if (data.value.toUpperCase().indexOf(text.toUpperCase()) > -1) {
                                                        $(node).parent().show();
                                                    } else {
                                                        $(node).parent().hide();
                                                    }
                                                }
                                            },
                                            width: 180,
                                            useRadius: false,
                                            isEnter: true
                                        },
                                        onSelectRow: function (rowId, status, event) {
                                            //兼容手动全选
                                            if (grid.datagrid("getSelectRowIds").length === resultKeysMap.length) {
                                                var selectAllBtn = dialog.find(".ui-jqgrid-hdiv").find("table").find("th:nth-child(2)").find("input[role=checkbox]");
                                                selectAllBtn.trigger("click");
                                            }
                                        }
                                    });
                                },
                                buttons: [{
                                    text: TempoUtils.locale('mine.publish-dialog-sure'),
                                    click: function () {
                                        var selectedData = grid.datagrid("getSelectRowData");
                                        if (!selectedData || selectedData.length <= 0) {
                                            var msg = '请至少选择一条数据操作';
                                            $("<div/>").alert({
                                                msg: msg
                                            });
                                            return;
                                        }
                                        headerTab.find("span").remove();
                                        var selectedShowData = [];
                                        //modify 2022-10-10 hanji 处理数据经过datagrid处理后不正确的问题，导致在筛选时出现点击确定后前端报错的问题
                                        selectedData.forEach(function (item) {
                                            var selectValue = groupsResult[item.value];
                                            try {
                                                selectValue.forEach(function (o) {
                                                    selectedShowData.push(o);
                                                });
                                            }catch (e) {
                                                console.log(item.value)
                                            }
                                        });
                                        selectedShowData.forEach(function (o) {
                                            showPortView(spanDiv, contentTab, container, o, window.constant.DATANODES.indexOf(o.nodeConfigId) == -1 || o.locType == 'result' || o.portType == "dataset", selectedShowData.length);
                                        });
                                        headerTab.find("span:first").css("border-left", "0px solid #d7dde5");
                                        headerTab.find("#backTop").remove();
                                        var backTop = $('<div title="返回顶部" id="backTop" style="position: absolute;cursor: pointer;right: 17px;bottom: 25px;width: 53px;height: 46px;background-color:rgba(242, 242, 242, 0.5)"><span class="ui-icon tempo-ui-icon" style="background-position:-432px -144px;margin: 5px 5px 5px 16px"></span><span style="margin: 0px 0px 5px 14px">顶部</span></span></div>').appendTo(headerTab);
                                        backTop.click(function () {
                                            headerTab.find(".tempo-mine-viewing-result-style")[0].scrollIntoView(false);
                                        });
                                        backTop.hover(function () {
                                            $(this).css("background-color", "rgba(242, 242, 242, 1)");
                                        }, function () {
                                            $(this).css("background-color", "rgba(242, 242, 242, 0.5)");
                                        });
                                        headerTab.find('.tempo-mine-viewing-result-style:first').trigger('click');
                                        dialog.dialog("close");
                                    }
                                }, {
                                    text: TempoUtils.locale('mine.publish-dialog-cancel'),
                                    click: function () {
                                        dialog.dialog("close");
                                    }
                                }]
                            });
                        }
                    });
                } else {
                    for (var key in groupsResult) {
                        groupsResult[key].forEach(function (o) {
                            showPortView(headerTab, contentTab, container, o, window.constant.DATANODES.indexOf(o.nodeConfigId) == -1 || o.locType == 'result' || o.portType == "dataset", resultKeys.length);
                        })
                    }
                }
            } else {
                for (var m = 0; m < result.length; m++) {
                    //显示端口页面
                    showPortView(headerTab, contentTab, container, result[m], window.constant.DATANODES.indexOf(result[m].nodeConfigId) == -1 || result[m].locType == 'result' || result[m].portType == "dataset", result.length)
                }
            }
        };

        var show = function (container) {
            //端口标题栏
            var headerTab = $("<div>").appendTo(container).css({'margin-bottom': '5px', 'overflow': 'auto'});
            //端口洞察页面
            var contentTab = $("<div>").appendTo(container);
            // 对洞察展示的端口顺序进行排序，模型显示在前面，其他显示在后面
            var ports = [];
            var models = [];
            var isSortFlag = true;
            result.forEach(function (e) {
                var insightData = JSON.parse(e.info);
                if (insightData.cycleLabel && (insightData.cycleLabel).length > 0) {
                    isSortFlag = false;
                }
                if (e.portType == 'node_default') {
                    models.push(e);
                } else if (e.portType == 'model') {
                    models.push(e);
                } else {
                    ports.push(e);
                }
            })
            if (isSortFlag) {
                result = models.concat(ports);//顺序为节点 模型 数据集 解决bug7641
            }
            if (result != null && result.length > 1) {
                if (result[0].nodeConfigId == "apriori" || result[0].nodeConfigId == "fpgrowth") {
                    var compare = function (v1, v2) {
                        p1 = v1.port;
                        p2 = v2.port;
                        if (p1 == "exa") {
                            p1 = "n";
                        }
                        if (p2 == "exa") {
                            p2 = "n";
                        }
                        return p1 > p2
                    }
                    result.sort(compare);
                } else if (result[0].nodeConfigId == "textTF") {
                    var result_tf = [];
                    var out_tf = [];
                    var exa_tf = [];
                    var graph_tf = [];
                    result.forEach(function (e) {
                        if (e.port == 'graph') {
                            graph_tf.push(e);
                        } else if (e.port == 'exa') {
                            exa_tf.push(e);
                        } else if (e.port == 'out') {
                            out_tf.push(e);
                        }
                    })
                    var i = 0;
                    while (exa_tf[i] || out_tf[i] || graph_tf[i]) {
                        if (exa_tf[i]) {
                            result_tf.push(exa_tf[i]);
                        }
                        if (out_tf[i]) {
                            result_tf.push(out_tf[i]);
                        }
                        if (graph_tf[i]) {
                            result_tf.push(graph_tf[i]);
                        }
                        i++;
                    }
                    result = result_tf;
                } else if (result[0].nodeConfigId == "partialcorr" || result[0].type == "minechart") {
                    var result_tf = [];
                    var out_tf = [];
                    var exa_tf = [];
                    var graph_tf = [];
                    result.forEach(function (e) {
                        if (e.port == 'graph') {
                            graph_tf.push(e);
                        } else if (e.port == 'exa') {
                            exa_tf.push(e);
                        }
                    })
                    var i = 0;
                    while (graph_tf[i] || exa_tf[i]) {
                        if (graph_tf[i]) {
                            result_tf.push(graph_tf[i]);
                        }
                        if (exa_tf[i]) {
                            result_tf.push(exa_tf[i]);
                        }
                        i++;
                    }
                    result = result_tf;
                } else if (result[0].nodeConfigId == "orderenvelope") {
                    // 对洞察展示的端口顺序进行排序，模型显示在前面，其他显示在后面
                    var ports = [];
                    var graphports = [];
                    result.forEach(function (e) {
                        if (e.portType == 'graph') {
                            graphports.push(e);
                        } else {
                            ports.push(e);
                        }
                    })
                    result = graphports.concat(ports);
                }
            }
            buildHeaderTab(headerTab, contentTab, container);
            var backTop = $('<div title="返回顶部" id="backTop" style="position: absolute;cursor: pointer;right: 17px;bottom: 25px;width: 53px;height: 46px;background-color:rgba(242, 242, 242, 0.5)"><span class="ui-icon tempo-ui-icon" style="background-position:-432px -144px;margin: 5px 5px 5px 16px"></span><span style="margin: 0px 0px 5px 14px">顶部</span></span></div>').appendTo(headerTab);
            backTop.click(function () {
                headerTab.find(".tempo-mine-viewing-result-style")[0].scrollIntoView(false);
            })
            backTop.hover(function () {
                $(this).css("background-color", "rgba(242, 242, 242, 1)");
            }, function () {
                $(this).css("background-color", "rgba(242, 242, 242, 0.5)");
            })
            //触发第一个端口的显示事件
            if (nodeTypeClickCache[nodeConfigId]) {
                var portName = nodeConfigId + "#" + nodeTypeClickCache[nodeConfigId];
                if (headerTab.find("span[name='" + portName + "']").length > 0) {
                    headerTab.find("span[name='" + portName + "']").trigger('click');
                } else {
                    if (nodeTypeClickCache[nodeConfigId].indexOf("model") > -1 && headerTab.find("span[name^='" + nodeConfigId + "#model" + "']").length == 1) {
                        headerTab.find("span[name^='" + nodeConfigId + "#model" + "']").trigger('click');
                    } else if (nodeTypeClickCache[nodeConfigId].indexOf("end") > -1 && headerTab.find("span[name^='" + nodeConfigId + "#end" + "']").length >= 1) {
                        //针对类子流程类的节点 洞察记忆处理
                        headerTab.find("span[name^='" + nodeConfigId + "#end" + "']").trigger('click');
                    } else {
                        headerTab.find('.tempo-mine-viewing-result-style:first').trigger('click');
                    }
                }
            } else {
                headerTab.find('.tempo-mine-viewing-result-style:first').trigger('click');
            }
        }
        //添加到tab页，并回掉show方法显示节点洞察内容
        addTab(nodeId, label, show, nodeConfigId)

    }
    //显示端口洞察
    var showPortView = function (headerTab, contentTab, container, insightResItem, isProcess, resultLen) {
        var tabSpan;
        var nodeConfigId = insightResItem.nodeConfigId;
        var portCode = nodeConfigId + "#" + insightResItem.port;
        //处理泰康在从5.1升级到6.1后  洞察页面的portType 为null
        var insightData = JSON.parse(insightResItem.info);
        var portType = insightResItem.portType || insightData.portType;
        if (!portType) {
            return;
        }
        var cycleLabel = "";

        if (insightData.cycleLabel && (insightData.cycleLabel).length > 0) {
            var newCycleLabel = insightData.cycleLabel;
            if (newCycleLabel.length > 20) {
                newCycleLabel = newCycleLabel.substring(0, 20) + "..."
            }
            cycleLabel = "(" + (newCycleLabel).replace("|", "-") + ")";
        }
        var isShowStatisticData = insightData.isShowStatisticData || insightData.showStatisticData;
        var resultStatisticData = insightData.resultStatisticData;
        var resultStatisticDataNom = insightData.resultStatisticDataNom;
        if (!isShowStatisticData) {
            if ((resultStatisticData && resultStatisticDataNom) && (resultStatisticData.length > 0 || resultStatisticDataNom.length > 0)) {
                isShowStatisticData = true;
            }
        }
        //数据集端口
        if (TempoMineUtils.isDataSet(portType)) {
            //如果是输入输出节点，则分开两个端口显示，一个原始数据，一个统计数据
            if (!isProcess) {
                $("<span class='tempo-mine-viewing-result-style' name='" + portCode + "' style='display: inline-block;'>").data('insightData', insightResItem).text(TempoUtils.locale("mine.originalData") + cycleLabel).appendTo(headerTab).click(function () {
                    contentTab.empty();
                    selectHeader($(this));
                    var insightData = JSON.parse($(this).data('insightData').info);
                    createResTable(insightData, contentTab);
                    var openData = $('<span style="cursor: pointer;margin-right: 10px;float: right;color: #00CCFF;margin-bottom: 13px;" title="查看前100行" id="openData">查看数据</span>')
                    contentTab.find('.tempo-mine-insight-table').before(openData);
                    openData.click(function () {
                        var a = TempoUtils.clone(insightData);
                        var flowName = "undefined" == typeof (currentInsightFlowName) ? ("undefined" == typeof (snapshotFlow) ? $('.tempo-mine-tab-curSelect').find('label').text() : snapshotFlow.flow.name) : currentInsightFlowName
                        if ((!flowName || flowName == null || flowName == "") && $(".navigator-path-text").length > 0) {
                            flowName = $(".navigator-path-text").text();
                        }
                        a.flowName = flowName;
                        a.nodeName = insightResItem.nodeLabel;
                        openUrlPost(contextPath + '/api/ai/mine/view/lookData', {'insightdata': JSON.stringify(a)}, TempoUtils.uuid())
                    })
                })
                if (isShowStatisticData) {
                    $("<span class='tempo-mine-viewing-result-style' name='" + portCode + "' style='display: inline-block;'>").data('insightData', insightResItem).text(TempoUtils.locale("mine.originalDataStatisticsInfo") + cycleLabel).appendTo(headerTab).click(function () {
                        selectHeader($(this));
                        contentTab.empty();
                        var insightData = JSON.parse($(this).data('insightData').info);
                        createResTableInfo1(insightData, contentTab, dataResultType.proceduce);
                        var openData = $('<span style="cursor: pointer;margin-right: 10px;float: right;color: #00CCFF;margin-bottom: 13px;" title="查看前100行" id="openData">查看数据</span>')
                        contentTab.find('.tempo-mine-insight-table').before(openData);
                        openData.click(function () {
                            var a = TempoUtils.clone(insightData);
                            var flowName = "undefined" == typeof (currentInsightFlowName) ? ("undefined" == typeof (snapshotFlow) ? $('.tempo-mine-tab-curSelect').find('label').text() : snapshotFlow.flow.name) : currentInsightFlowName
                            if ((!flowName || flowName == null || flowName == "") && $(".navigator-path-text").length > 0) {
                                flowName = $(".navigator-path-text").text();
                            }
                            a.flowName = flowName;
                            a.nodeName = insightResItem.nodeLabel;
                            openUrlPost(contextPath + '/api/ai/mine/view/lookData', {'insightdata': JSON.stringify(a)}, TempoUtils.uuid())
                        })
                    })
                }
            } else if (window.constant.TEXTMININGNODES.indexOf(insightResItem.nodeConfigId) != -1 || (insightData.nodeConfigId == "outlierdetection" && insightData.port == "out") || (insightData.nodeConfigId == "similaritiesmeasure" && insightData.port == "out")) {
                var tabName = (insightResItem.subProcessNodeId ? insightResItem.nodeLabel : '') + insightResItem.portLabel;
                var tabText = tabName;
                //处理空数据集下，循环行节点洞察显示null问题  已和需求沟通  要求不显示null
                if (cycleLabel != "(null)") {
                    tabText = tabName + cycleLabel;
                }
                tabSpan = $("<span class='tempo-mine-viewing-result-style' name='" + portCode + "' style='display: inline-block;'>").data('insightData', insightResItem)
                    .text(tabText).appendTo(headerTab)
                    .click(function (event) {
                        selectHeader($(this));
                        contentTab.empty();
                        var insightData = $(this).data('insightData');
                        //初始化算法参数界面
                        var pageParser = function (parent) {
                            return {
                                init: function (param) {
                                    param = param || {};
                                    var values = param.values || {};
                                    TempoUtils.parserUi(parent, values, $.noop);
                                }
                            }
                        }
                        var paramsConfig = MineFlowInfo.getParameters(insightData.nodeId);
                        $m.loadHtmlSyn(contextPath + '/api/ai/mine/' + window[window.constant.MNODES][insightData.nodeConfigId].datasetInsightPage,
                            contentTab, insightData.nodeId, {
                                parameters: paramsConfig,
                                source: contentTab,
                                insight: JSON.parse(insightData.info),
                                pageParser: pageParser,
                                nodeId: insightData.nodeId
                            });
                        if (insightData.nodeConfigId == "similaritiesmeasure") {
                            if (contentTab.find(".similartiesretable_descinfo span[id=openData]").length == 0) {
                                var openData = $('<span style="cursor: pointer;margin-right: 10px;float: right;color: #00CCFF;" title="查看前100行" id="openData">查看数据</span>')
                                $(contentTab.find(".similartiesretable_descinfo span")[0]).after(openData);
                                openData.click(function () {
                                    var a = TempoUtils.clone(insightData);
                                    var flowName = "undefined" == typeof (currentInsightFlowName) ? ("undefined" == typeof (snapshotFlow) ? $('.tempo-mine-tab-curSelect').find('label').text() : snapshotFlow.flow.name) : currentInsightFlowName
                                    if ((!flowName || flowName == null || flowName == "") && $(".navigator-path-text").length > 0) {
                                        flowName = $(".navigator-path-text").text();
                                    }
                                    a.flowName = flowName;
                                    a.nodeName = insightResItem.nodeLabel;
                                    a.resultTableData = JSON.parse(a.info).resultTableData;
                                    openUrlPost(contextPath + '/api/ai/mine/view/lookData', {'insightdata': JSON.stringify(a)}, TempoUtils.uuid())
                                })
                            }
                        } else if (insightData.nodeConfigId == "tmlda") {
                            if (contentTab.find('#openData').length == 0) {
                                var openData = $('<span style="cursor: pointer;margin-right: 10px;float: right;color: #00CCFF;" title="查看前100行" id="openData">查看数据</span></br>')
                                $(contentTab.children()[0]).before(openData);
                                openData.click(function () {
                                    var a = TempoUtils.clone(insightData);
                                    var flowName = "undefined" == typeof (currentInsightFlowName) ? ("undefined" == typeof (snapshotFlow) ? $('.tempo-mine-tab-curSelect').find('label').text() : snapshotFlow.flow.name) : currentInsightFlowName
                                    if ((!flowName || flowName == null || flowName == "") && $(".navigator-path-text").length > 0) {
                                        flowName = $(".navigator-path-text").text();
                                    }
                                    a.flowName = flowName;
                                    a.nodeName = insightResItem.nodeLabel;
                                    a.resultTableData = JSON.parse(a.info).resultDataset;
                                    openUrlPost(contextPath + '/api/ai/mine/view/lookData', {'insightdata': JSON.stringify(a)}, TempoUtils.uuid())
                                })
                            }
                        } else if (insightData.nodeConfigId == "ner" || insightData.nodeConfigId == "outlierdetection" || insightData.nodeConfigId == "textsimilarity") {
                            if (contentTab.find('#openData').length == 0) {
                                var openData = $('<span style="cursor: pointer;margin-right: 10px;float: right;color: #00CCFF;" title="查看前100行" id="openData">查看数据</span></br>')
                                $(contentTab.children()[0]).before(openData);
                                openData.click(function () {
                                    var a = TempoUtils.clone(insightData);
                                    var flowName = "undefined" == typeof (currentInsightFlowName) ? ("undefined" == typeof (snapshotFlow) ? $('.tempo-mine-tab-curSelect').find('label').text() : snapshotFlow.flow.name) : currentInsightFlowName
                                    if ((!flowName || flowName == null || flowName == "") && $(".navigator-path-text").length > 0) {
                                        flowName = $(".navigator-path-text").text();
                                    }
                                    a.flowName = flowName;
                                    a.nodeName = insightResItem.nodeLabel;
                                    a.resultTableData = JSON.parse(a.info).resultTableData;
                                    openUrlPost(contextPath + '/api/ai/mine/view/lookData', {'insightdata': JSON.stringify(a)}, TempoUtils.uuid())
                                })
                            }
                        } else if (insightData.nodeConfigId == "vsm" || insightData.nodeConfigId == "keywords") {
                            if (contentTab.find('#openData').length == 0) {
                                var openData = $('<span style="cursor: pointer;margin-right: 10px;float: right;color: #00CCFF;" title="查看前100行" id="openData">查看数据</span></br>')
                                $(contentTab.children()[0]).before(openData);
                                openData.click(function () {
                                    var a = TempoUtils.clone(insightData);
                                    var flowName = "undefined" == typeof (currentInsightFlowName) ? ("undefined" == typeof (snapshotFlow) ? $('.tempo-mine-tab-curSelect').find('label').text() : snapshotFlow.flow.name) : currentInsightFlowName
                                    if ((!flowName || flowName == null || flowName == "") && $(".navigator-path-text").length > 0) {
                                        flowName = $(".navigator-path-text").text();
                                    }
                                    a.flowName = flowName;
                                    a.nodeName = insightResItem.nodeLabel;
                                    a.resultTableData = JSON.parse(a.info).resultDataset;
                                    openUrlPost(contextPath + '/api/ai/mine/view/lookData', {'insightdata': JSON.stringify(a)}, TempoUtils.uuid())
                                })
                            }
                        } else if (insightData.nodeConfigId == "textTF" || insightData.nodeConfigId == "wordseg") {
                            if (contentTab.find('#openData').length == 0) {
                                var openData = $('<span style="cursor: pointer;margin-right: 10px;float: right;color: #00CCFF;" title="查看前100行" id="openData">查看数据</span></br>')
                                $(contentTab.children()[0]).before(openData);
                                openData.click(function () {
                                    var a = TempoUtils.clone(insightData);
                                    var flowName = "undefined" == typeof (currentInsightFlowName) ? ("undefined" == typeof (snapshotFlow) ? $('.tempo-mine-tab-curSelect').find('label').text() : snapshotFlow.flow.name) : currentInsightFlowName
                                    if ((!flowName || flowName == null || flowName == "") && $(".navigator-path-text").length > 0) {
                                        flowName = $(".navigator-path-text").text();
                                    }
                                    a.flowName = flowName;
                                    a.nodeName = insightResItem.nodeLabel;
                                    if (a.port == "exa") {
                                        a.resultTableData = JSON.parse(a.info).resultDataset;
                                    } else {
                                        a.resultTableData = JSON.parse(a.info).rsTableData;
                                    }
                                    openUrlPost(contextPath + '/api/ai/mine/view/lookData', {'insightdata': JSON.stringify(a)}, TempoUtils.uuid())
                                })
                            }

                            //modify 2022-10-19 hanji 处理循环行内部信息抽取节点查看数据出现多分的问题
                        } else if("informationextract" == insightData.nodeConfigId){
                            if (contentTab.find('#openData').length == 0) {
                                var openData = $('<span style="cursor: pointer;margin-right: 10px;float: right;color: #00CCFF;" title="查看前100行" id="openData">查看数据</span></br>')
                                $(contentTab.children()[0]).before(openData);
                                $(contentTab.parent().children()[0]).css("margin-bottom","0px");
                                openData.click(function () {
                                    var a = TempoUtils.clone(insightData);
                                    var flowName = "undefined" == typeof (currentInsightFlowName) ? ("undefined" == typeof (snapshotFlow) ? $('.tempo-mine-tab-curSelect').find('label').text() : snapshotFlow.flow.name) : currentInsightFlowName
                                    if ((!flowName || flowName == null || flowName == "") && $(".navigator-path-text").length > 0) {
                                        flowName = $(".navigator-path-text").text();
                                    }
                                    a.flowName = flowName;
                                    a.nodeName = insightResItem.nodeLabel;
                                    a.resultTableData = JSON.parse(a.info).resultDataset;
                                    openUrlPost(contextPath + '/api/ai/mine/view/lookData', {'insightdata': JSON.stringify(a)}, TempoUtils.uuid())
                                })
                            }
                        } else {
                            if (contentTab.parent().find('#openData').length == 0) {
                                var openData = $('<span style="cursor: pointer;margin-right: 10px;float: right;color: #00CCFF;" title="查看前100行" id="openData">查看数据</span>')
                                contentTab.parent().find('.tempo-mine-viewing-result-style').after(openData);
                                openData.click(function () {
                                    var a = TempoUtils.clone(insightData);
                                    var flowName = "undefined" == typeof (currentInsightFlowName) ? ("undefined" == typeof (snapshotFlow) ? $('.tempo-mine-tab-curSelect').find('label').text() : snapshotFlow.flow.name) : currentInsightFlowName
                                    if ((!flowName || flowName == null || flowName == "") && $(".navigator-path-text").length > 0) {
                                        flowName = $(".navigator-path-text").text();
                                    }
                                    a.flowName = flowName;
                                    a.nodeName = insightResItem.nodeLabel;
                                    a.resultTableData = JSON.parse(a.info).resultDataset;
                                    openUrlPost(contextPath + '/api/ai/mine/view/lookData', {'insightdata': JSON.stringify(a)}, TempoUtils.uuid())
                                })
                            }
                        }

                    });
            } else {
                //其他节点的默认加载数据集
                var tabName = (insightResItem.subProcessNodeId ? insightResItem.nodeLabel : '') + getPortLabel(insightResItem);
                var tabText = tabName;
                //处理空数据集下，循环行节点洞察显示null问题  已和需求沟通  要求不显示null
                if (cycleLabel != "(null)") {
                    tabText = tabName + cycleLabel;
                }
                tabSpan = $("<span class='tempo-mine-viewing-result-style' name='" + portCode + "' style='display: inline-block;'>").data('insightData', insightResItem)
                    .text(tabText).appendTo(headerTab)
                    .click(function (event) {
                        contentTab.empty();
                        selectHeader($(this));
                        var insightData = JSON.parse($(this).data('insightData').info);
                        if (insightData.nodeConfigId == "canonicalcorr") {
                            for (var x = 0; x < insightData.resultTableData.length; x++) {
                                var elem = insightData.resultTableData[x];
                                for (var y = 0; y < elem.length; y++) {
                                    if (elem[y] && (elem[y] == "Eigenvalue" || elem[y] == "Proportion" || elem[y] == "Cumulation" || elem[y].indexOf("_correlation_coefficient") != -1)) {
                                        var newelem = TempoUtils.locale("canonicalcorr." + elem[y]);
                                        insightData.resultTableData[x][y] = newelem;
                                    }
                                }
                            }
                        } else if (insightData.nodeConfigId == "anova") {
                            for (var x = 0; x < insightData.resultTableData.length; x++) {
                                var elem = insightData.resultTableData[x];
                                for (var y = 0; y < elem.length; y++) {
                                    if (insightData.port == "out" && (elem[y] == "df" || elem[y] == "Sum_of_squares" || elem[y] == "Mean_square" || elem[y] == "F" || elem[y] == "sig")) {
                                        var newelem = TempoUtils.locale("anova." + elem[y]);
                                        insightData.resultTableData[x][y] = newelem;
                                    }
                                }
                            }
                        } else if (insightData.nodeConfigId == "bayesnet") {
                            var flag = false;
                            var number = 0;
                            var fieldNames = insightData.resultTableData[1];
                            for (var n = 0; n < fieldNames.length; n++) {
                                if (fieldNames[n] == "probability") {
                                    number = n;
                                    flag = true;
                                }
                            }
                            //存在向量列
                            if (flag) {
                                //处理空数据集下 只有表头和数据类型 而导致数据集列表不展示问题
                                if (insightData.resultTableData.length > 2) {
                                    var ifArray = insightData.resultTableData[2][number];
                                    if ($.isArray(ifArray)) {
                                        for (var x = 2; x < insightData.resultTableData.length; x++) {
                                            var elem = insightData.resultTableData[x];
                                            for (var y = 0; y < elem[number].length; y++) {
                                                if (TempoMineUtils.format(elem[number][y]) == "0.9999") {
                                                    elem[number][y] = 1;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        } else if (insightData.nodeConfigId == "descriptivestatistics") {
                            for (var i = 0; i < insightData.resultTableData.length; i++) {
                                if (i != 1) {
                                    var dataItem = insightData.resultTableData[i];
                                    for (var j = 0; j < dataItem.length; j++) {
                                        var numItem = dataItem[j];
                                        if ($.isNumeric(numItem) && insightData.resultTableData[0][j] == "StringType") {
                                            insightData.resultTableData[0][j] = "number";
                                        }
                                    }
                                }
                            }
                        }
                        var inputPanel = $('<span style="font-weight: bold;padding: 10px; cursor: pointer;display: inline;font-size:14px;" id="inputPanel">' + TempoUtils.locale("mine.originalData") + '</span>').appendTo(contentTab);
                        if (isShowStatisticData) {
                            var sumPanel = $('<span style="font-weight: normal;padding: 10px; cursor: pointer;font-size:14px;" id="sumPanel">' + TempoUtils.locale("mine.originalDataStatisticsInfo") + '</span>').appendTo(contentTab);
                            sumPanel.click(function (e) {
                                rs.empty();
                                inputPanel.css('font-weight', 'normal');
                                sumPanel.css('font-weight', 'bold');
                                contentTab.find("#openData").css('display', 'none');
                                createResTableInfo1(insightData, rs, dataResultType.proceduce);
                            });
                        }
                        var rs = $('<div id="rs" style="margin-top: 10px;"></div>').appendTo(contentTab);
                        createResTable(insightData, rs);
                        rs.find('table:eq(0)').css('display', 'block');
                        rs.find('table:eq(1)').css('display', 'none');
                        inputPanel.click(function (e) {
                            rs.empty();
                            inputPanel.css('font-weight', 'bold');
                            contentTab.find("#openData").css('display', 'block');
                            if (sumPanel) {
                                sumPanel.css('font-weight', 'normal');
                            }
                            createResTable(insightData, rs);
                        });
                        contentTab.find('.tempo-mine-insight-table').css("display", "table");
                        setTimeout(function () {
                            //如果有直接删除，重新绘制
                            if (contentTab.find('#openData').length != 0) {
                                contentTab.find('#openData').remove();
                            }
                            //fix code：69393 空数据集统一展示 不针对特殊节点做适配
                            var openData = $('<span title="查看前100行" style="cursor: pointer;margin-right: 10px;float: right;color: #00CCFF" id="openData">查看数据</span>').insertAfter(contentTab.find("#inputPanel"));
                            openData.click(function () {
                                var a = TempoUtils.clone(insightData);
                                var flowName = "undefined" == typeof (currentInsightFlowName) ? ("undefined" == typeof (snapshotFlow) ? $('.tempo-mine-tab-curSelect').find('label').text() : snapshotFlow.flow.name) : currentInsightFlowName
                                if ((!flowName || flowName == null || flowName == "") && $(".navigator-path-text").length > 0) {
                                    flowName = $(".navigator-path-text").text();
                                }
                                a.flowName = flowName;
                                a.nodeName = insightResItem.nodeLabel;
                                openUrlPost(contextPath + '/api/ai/mine/view/lookData', {'insightdata': JSON.stringify(a)}, TempoUtils.uuid())
                            })
                        }, 10)
                    });
            }
        }
        else if (TempoMineUtils.isModel(portType)) {
            var tabName = (insightResItem.subProcessNodeId ? insightResItem.nodeLabel : '') + getPortLabel(insightResItem);
            var tabText = tabName;
            //处理空数据集下，循环行节点洞察显示null问题  已和需求沟通  要求不显示null
            if (cycleLabel != '(null)') {
                tabText = tabName + cycleLabel;
            }
            // 获取自定义算法标识
            var isUserDefined = insightData.isUserDefined;
            // 自定义算法语言类型
            var lang = insightData.lang;
            if(isUserDefined && "python" === lang.toLowerCase()) {
                // 从port中截取模型端口的标识
                var suffix = insightData.port.substring(6, insightData.port.length);
                tabText = tabName + suffix;
            }
            tabSpan = $("<span class='tempo-mine-viewing-result-style' name='" + portCode + "' style='display: inline-block;'>").data('insightData', insightResItem)
                .text(tabText).appendTo(headerTab)
                .click(function (event) {
                    var insightInfo = $(this).data('insightData');
                    contentTab.empty();
                    selectHeader($(this));
                    //初始化算法参数界面
                    var pageParser = function (parent) {
                        return {
                            init: function (param) {
                                param = param || {};
                                var values = param.values || {};
                                TempoUtils.parserUi(parent, values, $.noop);
                            }
                        }
                    }
                    var configParentDiv = $('<div class="tempo-mine-alg-config-page">').appendTo(contentTab);
                    if (window.constant.INDIRECTLOADMNODES.indexOf(insightResItem.nodeConfigId) != -1) {
                        var paramsConfig = MineFlowInfo.getParameters(insightResItem.nodeId);
                        var insightData = JSON.parse(insightInfo.info);
                        var algNodeInsightInfo = insightData.algNodeModelInsightInfo;
                        if (typeof algNodeInsightInfo == "string") {
                            algNodeInsightInfo = JSON.parse(algNodeInsightInfo);
                        }
                        while (algNodeInsightInfo != null && algNodeInsightInfo.algNodeModelInsightInfo != null) {
                            algNodeInsightInfo = algNodeInsightInfo.algNodeModelInsightInfo;
                            if (typeof algNodeInsightInfo == "string") {
                                algNodeInsightInfo = JSON.parse(algNodeInsightInfo);
                            }
                        }
                        if (algNodeInsightInfo != null) {

                            var algNodeConfigId = algNodeInsightInfo.producerNodeTypeId;
                            if (window.constant.CLUSTERNODES.indexOf(algNodeConfigId) != -1) {
                                if (algNodeInsightInfo.nodeConfigId == 'vcluster') {
                                    showClusterResPic1(algNodeInsightInfo, configParentDiv);
                                    if (window[window.constant.MNODES][algNodeInsightInfo.producerNodeTypeId].frameInsightPage) {
                                        var paramsConfig = MineFlowInfo.getParameters(algNodeInsightInfo.producerNodeId);
                                        if (paramsConfig) {
                                            var clusterNodeInsightDiv = $("<div/>").appendTo(configParentDiv);
                                            $m.loadHtmlSyn(contextPath + '/api/ai/mine/' + window[window.constant.MNODES][algNodeInsightInfo.producerNodeTypeId].frameInsightPage,
                                                clusterNodeInsightDiv, algNodeInsightInfo.producerNodeId, {
                                                    source: clusterNodeInsightDiv,
                                                    insight: algNodeInsightInfo,
                                                    parameters: paramsConfig,
                                                    dialog: pageParser(clusterNodeInsightDiv)
                                                });
                                        }
                                    }
                                } else {
                                    if (window[window.constant.MNODES][algNodeInsightInfo.producerNodeTypeId].frameInsightPage) {
                                        var paramsConfig = MineFlowInfo.getParameters(algNodeInsightInfo.producerNodeId);
                                        if (paramsConfig) {
                                            var clusterNodeInsightDiv = $("<div/>").appendTo(configParentDiv);
                                            $m.loadHtmlSyn(contextPath + '/api/ai/mine/' + window[window.constant.MNODES][algNodeInsightInfo.producerNodeTypeId].frameInsightPage,
                                                clusterNodeInsightDiv, algNodeInsightInfo.producerNodeId, {
                                                    source: clusterNodeInsightDiv,
                                                    insight: algNodeInsightInfo,
                                                    parameters: paramsConfig,
                                                    dialog: pageParser(clusterNodeInsightDiv)
                                                });
                                        }
                                    }
                                    showClusterResPic1(algNodeInsightInfo, configParentDiv);
                                }

                            } else if (window.constant.FEATUREREDUCENODES.indexOf(algNodeConfigId) != -1) {
                                $m.loadHtmlSyn(contextPath + '/api/ai/mine/' + window[window.constant.MNODES][algNodeInsightInfo.producerNodeTypeId].datasetInsightPage, configParentDiv, algNodeInsightInfo.producerNodeId, {
                                    source: configParentDiv,
                                    insight: algNodeInsightInfo,
                                    dialog: pageParser(configParentDiv)
                                });
                            } else if ("autoclustering" == algNodeConfigId) {
                                var algNodeModelInsightInfo = JSON.parse(insightInfo.info).algNodeModelInsightInfo;
                                if (typeof algNodeModelInsightInfo == "string") {
                                    algNodeModelInsightInfo = JSON.parse(algNodeInsightInfo);
                                }
                                showClusterResPic1(algNodeModelInsightInfo, contentTab, "auto");
                            } else if (algNodeConfigId == "ahp" || algNodeConfigId == "fce") {
                                configParentDiv.empty();
                                var paramsConfig = MineFlowInfo.getParameters(algNodeInsightInfo.producerNodeId);
                                $m.loadHtmlSyn(contextPath + '/api/ai/mine/' + window[window.constant.MNODES][algNodeInsightInfo.producerNodeTypeId].frameInsightPage, configParentDiv, algNodeInsightInfo.producerNodeId, {
                                    source: configParentDiv,
                                    insight: algNodeInsightInfo,
                                    parameters: paramsConfig,
                                    dialog: pageParser(configParentDiv)
                                });

                            } else if (algNodeInsightInfo.producerNodeCategory == "pmml") {
                                TempoMineInsightUtils.showPMMLModelInsight(algNodeInsightInfo, contentTab);
                            } else {
                                var paramsConfig = MineFlowInfo.getParameters(algNodeInsightInfo.producerNodeId || insightData.producerNodeId);
                                $m.loadHtmlSyn(contextPath + '/api/ai/mine/' + window[window.constant.MNODES][algNodeInsightInfo.producerNodeTypeId || insightData.producerNodeTypeId].frameInsightPage, configParentDiv, algNodeInsightInfo.producerNodeId, {
                                    source: configParentDiv,
                                    insight: algNodeInsightInfo,
                                    parameters: paramsConfig,
                                    dialog: pageParser(configParentDiv)
                                });
                            }
                            // 给模型读取节点的洞察增加模型名称和版本号
                            if(insightResItem.nodeConfigId == "readmodel" && algNodeInsightInfo.modelName != null && algNodeInsightInfo.modelVersion != null){
                                var tag = "利用的模型名称：" + algNodeInsightInfo.modelName + "；版本号：" + algNodeInsightInfo.modelVersion + "。";
                                var downLoadBtn = "<div style='margin-bottom: 10px'><span'>" + tag + "</span></div>";
                                configParentDiv.prepend(downLoadBtn);
                            }

                        }
                    } else if (window.constant.CLUSTERNODES.indexOf(insightResItem.nodeConfigId) != -1) {
                        if (insightResItem.nodeConfigId == 'vcluster') {
                            showClusterResPic1(JSON.parse(insightInfo.info), contentTab);
                            if (window[insightInfo.type][insightInfo.nodeConfigId].frameInsightPage) {
                                var paramsConfig = MineFlowInfo.getParameters(insightResItem.nodeId);
                                if (paramsConfig) {
                                    var clusterNodeInsightDiv = $("<div/>").appendTo(contentTab);
                                    $m.loadHtmlSyn(contextPath + '/api/ai/mine/' + window[window.constant.MNODES][insightInfo.nodeConfigId].frameInsightPage,
                                        clusterNodeInsightDiv, insightResItem.nodeId, {
                                            source: clusterNodeInsightDiv,
                                            insight: insightInfo,
                                            parameters: paramsConfig,
                                            dialog: pageParser(clusterNodeInsightDiv)
                                        });
                                }
                            }
                        } else {
                            if (window[insightInfo.type][insightInfo.nodeConfigId].frameInsightPage) {
                                var paramsConfig = MineFlowInfo.getParameters(insightResItem.nodeId);
                                if (paramsConfig) {
                                    var clusterNodeInsightDiv = $("<div/>").appendTo(contentTab);
                                    $m.loadHtmlSyn(contextPath + '/api/ai/mine/' + window[window.constant.MNODES][insightInfo.nodeConfigId].frameInsightPage,
                                        clusterNodeInsightDiv, insightResItem.nodeId, {
                                            source: clusterNodeInsightDiv,
                                            insight: insightInfo,
                                            parameters: paramsConfig,
                                            dialog: pageParser(clusterNodeInsightDiv)
                                        });
                                }
                            }
                            showClusterResPic1(JSON.parse(insightInfo.info), contentTab);
                        }
                    } else if (insightResItem.nodeConfigId == "pca" || insightResItem.nodeConfigId == "factor" || insightResItem.nodeConfigId == "svd" || insightResItem.nodeConfigId == "binning") {
                        selectHeader($(this));
                        contentTab.empty();
                        var insightData = $(this).data('insightData');
                        //初始化算法参数界面
                        var pageParser = function (parent) {
                            return {
                                init: function (param) {
                                    param = param || {};
                                    var values = param.values || {};
                                    TempoUtils.parserUi(parent, values, $.noop);
                                }
                            }
                        }
                        var paramsConfig = MineFlowInfo.getParameters(insightData.nodeId);
                        $m.loadHtmlSyn(contextPath + '/api/ai/mine/' + window[window.constant.MNODES][insightData.nodeConfigId].datasetInsightPage,
                            contentTab, insightData.nodeId, {
                                parameters: paramsConfig,
                                source: contentTab,
                                insight: JSON.parse(insightData.info),
                                pageParser: pageParser,
                                nodeId: insightData.nodeId
                            });
                    } else if (insightResItem.nodeConfigId == "autoclustering") {
                        showClusterResPic1(JSON.parse(insightInfo.info), contentTab, "auto");
                    } else if (insightResItem.nodeConfigId == "pmmlapplymodel" || insightResItem.nodeConfigId == "readpmmlmodel") {
                        var insightData = JSON.parse(insightInfo.info);
                        var algNodeInsightInfo = insightData.algNodeModelInsightInfo;
                        while (algNodeInsightInfo.algNodeModelInsightInfo != null) {
                            algNodeInsightInfo = algNodeInsightInfo.algNodeModelInsightInfo;
                        }
                        TempoMineInsightUtils.showPMMLModelInsight(algNodeInsightInfo, contentTab);
                    } else if ("pythonscript" == insightResItem.nodeConfigId || (isUserDefined && "python" === lang.toLowerCase())) {
                        var paramsConfig = MineFlowInfo.getParameters(insightResItem.nodeId);
                        if (paramsConfig && window[window.constant.MNODES][insightResItem.nodeConfigId].modelInsightPage) {
                            contentTab.empty();
                            $m.loadHtmlSyn(contextPath + '/api/ai/mine/' + window[window.constant.MNODES][insightResItem.nodeConfigId].modelInsightPage, contentTab, insightResItem.nodeId, {
                                source: contentTab,
                                insight: JSON.parse(insightInfo.info),
                                parameters: paramsConfig,
                                dialog: pageParser(contentTab)
                            });
                        }
                    } else {
                        var paramsConfig = MineFlowInfo.getParameters(insightResItem.nodeId);
                        if (paramsConfig && window[window.constant.MNODES][insightResItem.nodeConfigId].frameInsightPage) {
                            contentTab.empty();
                            $m.loadHtmlSyn(contextPath + '/api/ai/mine/' + window[window.constant.MNODES][insightResItem.nodeConfigId].frameInsightPage, contentTab, insightResItem.nodeId, {
                                source: contentTab,
                                insight: JSON.parse(insightInfo.info),
                                parameters: paramsConfig,
                                dialog: pageParser(contentTab)
                            });
                        }
                    }
                });
        } else if (!TempoMineUtils.isNotDefaultPort(portType)) {
            if (insightData.type == "dm_stream") {
                $("<span class='tempo-mine-viewing-result-style' name='" + portCode + "' style='display: inline-block;'>").data('insightData', insightResItem).text(TempoUtils.locale("mine.originalData") + cycleLabel).appendTo(headerTab).click(function () {
                    contentTab.empty();
                    selectHeader($(this));
                    var insightInfo = $(this).data('insightData');
                    var insightData = JSON.parse(insightInfo.info);
                    var paramsConfig = MineFlowInfo.getParameters(insightInfo.nodeId)
                    $m.loadHtmlSyn(contextPath + '/api/ai/mine/' + window[window.constant.DATAMINE_STREAM][insightInfo.nodeConfigId].datasetInsightPage,
                        contentTab, insightInfo.nodeId, {
                            source: contentTab,
                            insight: insightData,
                            parameters: paramsConfig
                        });
                })
                if (isShowStatisticData) {
                    $("<span class='tempo-mine-viewing-result-style'name='" + portCode + "' style='display: inline-block;'>").data('insightData', insightResItem).text(TempoUtils.locale("mine.originalDataStatisticsInfo") + cycleLabel).appendTo(headerTab).click(function () {
                        selectHeader($(this));
                        contentTab.empty();
                        var insightData = JSON.parse($(this).data('insightData').info);
                        createResTableInfo1(insightData, contentTab, dataResultType.proceduce);
                    })
                }
            } else {
                var tabName = (insightResItem.subProcessNodeId ? insightResItem.nodeLabel : '') + TempoUtils.locale("mine.jiedian");
                var tabText = tabName;
                //处理空数据集下，循环行节点洞察显示null问题  已和需求沟通  要求不显示null
                if (cycleLabel != "(null)") {
                    tabText = tabName + cycleLabel;
                }
                tabSpan = $("<span class='tempo-mine-viewing-result-style' name='" + portCode + "' style='display: inline-block;'>").data('insightData', insightResItem)
                    .text(tabText).appendTo(headerTab)
                    .click(function (event) {
                        selectHeader($(this));
                        contentTab.empty();
                        var insightInfo = $(this).data('insightData');
                        var insightData = JSON.parse(insightInfo.info);
                        contentTab.empty();
                        var paramsConfig = MineFlowInfo.getParameters(insightInfo.nodeId)
                        $m.loadHtmlSyn(contextPath + '/api/ai/mine/' + window[window.constant.MNODES][insightInfo.nodeConfigId].frameInsightPage,
                            contentTab, insightInfo.nodeId, {
                                source: contentTab,
                                insight: insightData,
                                parameters: paramsConfig
                            });
                    });
            }
        } else if (TempoMineUtils.isGraph(portType)) {
            var tabName = (insightResItem.subProcessNodeId ? insightResItem.nodeLabel : '') + getPortLabel(insightResItem);
            var tabText = tabName;
            //处理空数据集下，循环行节点洞察显示null问题  已和需求沟通  要求不显示null
            if (cycleLabel != "(null)") {
                tabText = tabName + cycleLabel;
            }
            tabSpan = $("<span class='tempo-mine-viewing-result-style' name='" + portCode + "' style='display: inline-block;'>").data('insightData', insightResItem)
                .text(tabText).appendTo(headerTab)
                .click(function (event) {
                    selectHeader($(this));
                    contentTab.empty();
                    var insightInfo = $(this).data('insightData');
                    var insightData = JSON.parse(insightInfo.info);
                    contentTab.empty();
                    var paramsConfig = MineFlowInfo.getParameters(insightInfo.nodeId);
                    $m.loadHtmlSyn(contextPath + '/api/ai/mine/' + window[window.constant.MNODES][insightInfo.nodeConfigId].frameInsightPage,
                        contentTab, insightInfo.nodeId, {
                            source: contentTab,
                            insight: insightData,
                            parameters: paramsConfig
                        });
                });
        }
        else if (TempoMineUtils.isSignal(portType)) {
            //如果是信号节点，则分开两个端口显示，一个节点，一个信号数据集
            //信号模块洞察调整，将信号数据集和节点位置互换，将波形图和输出数据位置互换
            //信号数据集
            if (insightData.isShowSignalData || insightData.showSignalData) {
                //信号数据集
                $("<span class='tempo-mine-viewing-result-style' name='" + nodeConfigId + "#" + "signal' style='display: inline-block;'>").data('insightData', insightResItem)
                    .text("信号数据集").appendTo(headerTab)
                    .click(function (event) {
                        contentTab.empty();
                        selectHeader($(this));
                        var insightData = JSON.parse($(this).data('insightData').info);
                        //判断是否为信号节点
                        insightData.flag = window.mineConstant.PORT_SIGNAL;
                        signalDataShow(contentTab, insightData, insightData.isShowWaveFrom || insightData.showWaveFrom, insightResItem);
                    });
            }
            //节点
            if (insightData.isShowNodeData || insightData.showNodeData) {
                $("<span class='tempo-mine-viewing-result-style' name='" + nodeConfigId + "#" + "node' style='display: inline-block;'>").data('insightData', insightResItem)
                    .text("节点").appendTo(headerTab)
                    .click(function (event) {
                        contentTab.empty();
                        selectHeader($(this));
                        var insightData = JSON.parse($(this).data('insightData').info);
                        $m.loadHtmlSyn(contextPath + '/api/ai/mine/' + window[window.constant.DATAMINE_SIGNAL][insightData.nodeConfigId].frameInsightPage,
                            contentTab, insightData.nodeId, {source: contentTab, insight: insightData});
                    });
            }
        } else {
            var insightResItem = event.data;
            var insightId = $(this).data('insightId');
            getPortInsight(insightId, function (insightInfo) {
                var insightInfo = event.data[0];
                var insightResItem = event.data[1];
                $m.loadHtmlSyn(contextPath + '/api/ai/mine/' + window[insightInfo.type][insightInfo.nodeConfigId].frameInsightPage,
                    oDivData, insightResItem.nodeId, {source: oDivData, insight: insightInfo});
            })
        }
        if(tabSpan){
            if(resultLen > 20){
                tabSpan.css({
                    "width": 100,
                    "white-space": "nowrap",
                    "overflow": "hidden",
                    "text-overflow": "ellipsis",
                    "border-left": "none"
                })
            }
            tabSpan.attr("title", tabText);
            if (insightData.cycleLabel && (insightData.cycleLabel).length > 20) {
                tabSpan.attr("title", tabName + "(" + insightData.cycleLabel + ")");
            }
        }
    }


    /**
     * 缓存流程信息，用来节点信息获取
     * */
    var cacheFlowData = function (param) {
        var flowData = null;
        try {
            flowData = JSON.parse(param);
        } catch (e) {
            return {};
        }
        var data = processChildrenPosition(flowData.children);
        MineFlowInfo = (function () {
            return {
                getParameters: function (id) {
                    /**
                     * 获取节点配置信息（包含子流程内部节点）
                     */
                    var _findData = function (pathId, navData) {
                        var navId = navData.eid;
                        if (navId == pathId) {
                            return navData.parameters;
                        } else {
                            if (navData.process) {
                                navId = navData.process.id;
                                navData = navData.process.flow;
                            }
                            if (navData && navData.children) {
                                var navs = navData.children;
                                if (navs) {
                                    for (var i = 0; i < navs.length; i++) {
                                        var nav = navs[i];
                                        var data = _findData(pathId, nav);
                                        if (data != null) {
                                            return data;
                                        }
                                    }
                                }
                            }
                        }
                    };
                    if (flowData && flowData.children) {
                        return _findData(id, flowData);
                    }
                    return {};
                }
            }
        })();
    }


    //初始化流程
    var initFlow = function () {
        var panel = $("#tempo-mine-viewing-flowpanel");
        if (!panel || panel.size() == 0) {
            panel = $('#fc-flowgraph');
            if (panel.hasClass('tempo-mine-flow-container')) {
                panel.flowpanel('destroy');
            }
        }
        var tabs = $('#tempo-mine-viewing-resultshow').empty();
        if (tabs.hasClass('tempo-tabs') && tabs.hasClass('ui-tabs')) {
            tabs.tabs("destroy");
        }
        if ($('#tempo-mine-viewing').length == 0) {
            console.log('Nothing found.');
            return;
        }
        var process = $("<div/>").tempoprogressbar();
        //获取流程信息
        $.postForm({
            url: contextPath + getUrl("processInfo", "/api/ai/mine/searchProcessInsightInfo"),
            data: {
                flowId: pid,
                serviceid: pid,
                flowid: window.flowid,
                exeId: exeId,//可传可不传的参数
            },
            complete: function () {
                process.tempoprogressbar("destroy");
            },
            success: function (result) {
                window.onlyShowFlow = false;
                if ($('#tempo-mine-viewing').length == 0) {
                    console.log('Nothing found.');
                    return;
                }
                if (!result || result == "") {
                    console.log('Nothing found.');
                    return;
                }
                //解决 流程执行到循环行节点时就可以切换到洞察页面并导出word
                if (result.processData != null && result.processData != undefined && result.processData != "") {
                    if (result.processData.desc.durationTime == undefined
                        || result.processData.desc.durationTime == ""
                        || result.processData.desc.durationTime == null) {
                        return;
                    }
                }
                if (result && result.success && result.data) {
                    result = result.data;
                    if (result.processData) {
                        result.processData = JSON.parse(result.processData);
                    }
                    if (result.pname && result.pname != 'null') {
                        window.currentInsightFlowName = result.pname;
                    }
                }
                //获取洞察数据
                var insightData = result.processData;
                //如果是管道流程则显示下载Mleap文件按钮及下拉菜单按钮
                //获取流程类型
                var flowType = result.flowType || result.FLOWTYPE;
                //是否隐藏下载MLeap文件按钮及下拉菜单按钮的标识（普通流程需要隐藏）
                var isHidden = true;
                //只有洞察页面可以下载，洞察页面才显示按钮
                if (flowType == "plflow" && window.apiInsight != "inline") {
                    isHidden = false;
                    mLeapModelIfExists();
                }
                //流程面板
                panel.flowpanel({
                    withLogger: false,
                    flowType: flowType,
                    id: 'flowgraph',
                    customBtns: [{
                        text: TempoUtils.locale("mine.fangda"),
                        icon: 'ui-icon tempo-ui-icon tempo-ui-icon-insight-zoomout tempo-mine-button',
                        click: function () {
                            if (result != "") {
                                var zoom = panel.flowpanel('option', 'transform') || 100;
                                panel.flowpanel('option', 'transform', zoom + 10)
                                panel.flowpanel('zoomBorder');
                            }
                        }
                    }, {
                        text: TempoUtils.locale("mine.suoxiao"),
                        icon: 'ui-icon tempo-ui-icon tempo-ui-icon-insight-zoomin tempo-mine-button',
                        click: function () {
                            if (result != "") {
                                var zoom = panel.flowpanel('option', 'transform') || 100;
                                panel.flowpanel('option', 'transform', zoom - 10);
                                panel.flowpanel('zoomBorder');
                            }
                        }
                    }, {
                        text: "下载Mleap文件",
                        icon: 'ui-icon tempo-ui-icon tempo-ui-icon-insight-downmleapfile tempo-mine-button',
                        hidden: isHidden,
                        click: function (ele) {
                            //流程失败则不能下载
                            if (flowIsFailed || !mLeapModelIsExists) {
                                return;
                            }
                            modelDownLoadLimitCheck();
                        }
                    }, {
                        text: "",
                        icon: 'ui-icon tempo-ui-icon tempo-ui-icon-insight-downselectfile tempo-mine-button',
                        hidden: isHidden,
                        userDefStyle: true,
                        click: function (ele) {
                            OpenMLeapSelectDialog(ele);
                        }

                    }, {
                        text: TempoUtils.locale("mine.daochuword"),
                        icon: 'ui-icon tempo-ui-icon tempo-ui-icon-insight-msdoc tempo-mine-button',
                        click: function () {
                            openDialog(result, pid);
                        }
                    }, {
                        icon: 'split-btn',
                        type: 'spliter'
                    }
                        , {
                            icon: 'ui-icon tempo-ui-icon tempo-mine-button tempo-ui-icon-uparrows-undertint',
                            click: function () {
                                var icon = $(this).find('span');
                                if (icon.hasClass('tempo-ui-icon-uparrows-undertint')) {
                                    icon.removeClass('tempo-ui-icon-uparrows-undertint');
                                    icon.addClass('tempo-ui-icon-downarrows-undertint');
                                    panel.layout().close('center');
                                    $('#tempo-mine-viewing').layout().sizePane('north', 32);
                                } else {
                                    icon.removeClass('tempo-ui-icon-downarrows-undertint');
                                    icon.addClass('tempo-ui-icon-uparrows-undertint');
                                    $('#tempo-mine-viewing').layout().sizePane('north', 280);
                                }
                                //69992 处理1366分辨率下洞察页面多个页签，点击洞察收起放下图标后洞察页面高度为自适应问题
                                //参考tempo-tabs组件中的_addArrow方法，同步修改高度
                                var tabs = $('#tempo-mine-viewing-resultshow');
                                if (tabs && tabs.length > 0) {
                                    var height = tabs.height();
                                    var tabListHeight = tabs.find("ul[role='tablist']").outerHeight(true);
                                    tabs.find(".ui-tabs-panel").outerHeight(height - tabListHeight);
                                }
                            }
                        }]
                });
                var icon = panel.find('.tempo-ui-icon-uparrows-undertint');
                if (icon && icon.size() > 0) {
                    icon.removeClass('tempo-ui-icon-downarrows-undertint');
                    icon.addClass('tempo-ui-icon-uparrows-undertint');
                    $('#tempo-mine-viewing').layout().sizePane('north', 280);
                }
                //绘制流程图
                loadInputdata(pid, panel.flowpanel('getBoard'), cacheFlowData, panel, result);
                if (!result || !result.processData || !result.processData.desc || !result.processData.desc.durationTime) {
                    $('#tempo-mine-viewing').layout().sizePane('north', $('#tempo-mine-viewing').height());
                    window.onlyShowFlow = true;
                    return;
                }
                tabs.append('<ul>');
                tabs.tabs({
                    heightStyleType: 'fill',
                    activate: function (event, ui) {
                        var nodeid = ui.newPanel.attr('id');
                        panel.find('.tempo-basenode-select').removeClass('tempo-basenode-select');
                        panel.find('#' + nodeid).addClass('tempo-basenode-select');

                    }
                });
                //流程描述
                var showDesc = function (descDiv) {
                    var descData = insightData.desc;
                    descData.PNAME = result.PNAME;
                    descData.THEMENAME = result.THEMENAME;
                    rendOverViewDesc(descDiv, descData);
                }
                //综述tab页
                addTab('desc', TempoUtils.locale("mine.summarize"), showDesc);
            }
        });

    }
    //打开导出word对话框
    var openDialog = function (result, pid) {
        var dialog = $("<div/>").appendTo($("body")).dialog({
            title: TempoUtils.locale("mine.exportWordDialogTitle"),
            height: 195,
            width: 500,
            modal: true,
            draggable: true,
            resizable: false,
            buttons: [{
                text: TempoUtils.locale("mine.publish-dialog-sure"),
                type: "ok",
                click: function (e) {
                    var datalength = dialog.find("input[name=datalength]").val();
                    if (/^([0-9]|[1-9][0-9]|[1][0][0])$/.test(datalength) && datalength.indexOf(".") == -1) {
                        if (result != "") {
                            if (exeId) {
                                if (window.updateview) {
                                    window.open(contextPath + "/api/ai/mine/view/insight/preview/page?exeId=" + exeId + "&fId=" + pid + "&datalength=" + datalength + "&mode=block#" + pid, '_blank')
                                } else {
                                    window.open(contextPath + "/api/ai/mine/view/insight/preview/page?exeId=" + exeId + "&fId=" + pid + "&datalength=" + datalength + "&mode=" + (window.apiInsight || 'block') + "#" + pid, '_blank')
                                }
                            } else {
                                if (window.updateview) {
                                    window.open(contextPath + "/api/ai/mine/view/insight/preview/page?fId=" + pid + "&datalength=" + datalength + "&mode=block#" + pid, '_blank')
                                } else {
                                    window.open(contextPath + "/api/ai/mine/view/insight/preview/page?fId=" + pid + "&datalength=" + datalength + "&mode=" + (window.apiInsight || 'block') + "#" + pid, '_blank')
                                }
                            }
                        }
                        dialog.dialog("destroy").remove();
                    } else {
                        $("<div/>").alert({
                            msg: "该项为必填项，并且仅支持0~100的整数",
                            title: TempoUtils.locale("mine.prompt")
                        });
                    }
                }
            }, {
                text: TempoUtils.locale("mine.publish-dialog-cancel"),
                click: function (e) {
                    dialog.dialog("destroy").remove();
                }
            }],
            hide: {
                effect: 'fade',
                duration: 300
            },
            open: function () {
                var ui = $(this);
                $("<span>").appendTo(ui).text(TempoUtils.locale("mine.exportWordDialogContent1"));
                var value = $('<input name="datalength">').appendTo(ui)
                    .validatebox({
                        width: 60,
                        height: 28,
                        required: true,
                        validator: true,
                        value: "10",
                        // valids:[/^([0-9]|[1-9][0-9]|[1][0][0])$/],
                        // tip:TempoUtils.locale("mine.exportWordDialogContent4"),
                        maxLength: 60,
                    })
                $("<span>").appendTo(ui).text(TempoUtils.locale("mine.exportWordDialogContent2"));
                $("<span>").appendTo(ui).css("position", "absolute").css("width", "16px").css("height", "16px").css("display", "inline-block")
                    .css("background", "url(" + contextPath + "/util/utilconfig/css/images/tips.png)").css("line-height", "30px").css("margin-top", "6px").attr("title", "仅支持输入0~100的整数，默认值为10");
                $("<span>").appendTo(ui)
                $("<br>").appendTo(ui).text(TempoUtils.locale("mine.exportWordDialogContent2"));
                $("<span>").appendTo(ui).text(TempoUtils.locale("mine.exportWordDialogContent3")).css("color", "blue");

            },
            close: function () {
                $(this).dialog("destroy").remove();
            }
        });
    }

    /**
     * 校验MLeap模型是否存在，判断洞察下载MLeap按钮是否置灰
     */
    var mLeapModelIfExists = function () {
        $.ajax({
            url: contextPath + "/api/ai/mine/sync/mleap-model-if-exists",
            type: 'post',
            async: false,
            data: {
                //流程id
                flowId: pid,
                //应用id
                themeId: window[constant.ANALYSE_ID],
                //类型 "mleap"代表MLeap模型
                modelType: "mleap",
            },
            success: function (rs) {
                mLeapModelIsExists = rs.success;
            }
        });
    }

    /**
     * 进行模型下载限制校验
     */
    var modelDownLoadLimitCheck = function () {
        //进行模型下载限制校验
        var process = $("<div/>").tempoprogressbar();
        $.ajax({
            url: contextPath + '/api/ai/model/download/limit/download-check',
            data: {
                moduleName: 'model-offline-download',
            },
            type: 'POST',
            success: function (result) {
                if (result.success) {
                    if (result.data) {
                        $('<div/>').alert({
                            msg: '由于开启离线模型下载次数限制，请在发布区下载管道服务包',
                            width:420,
                            height:200
                        });
                    } else {
                        //无数据则说明不需要对MLeap模型进行下载限制，直接下载
                        downloadMLeapModel();
                    }
                } else {
                    //接口调用报错提示
                }
            },
            complete: function () {
                process.tempoprogressbar("destroy");
            },
            error: function () {
            }
        });
    };

    /**
     * 下载MLeap模型文件
     */
    var downloadMLeapModel = function () {
        //先调用接口判断文件是否存在
        $.ajax({
            url: contextPath + "/api/ai/mine/sync/mleap-model-if-exists",
            type: 'post',
            data: {
                //流程id
                flowId: pid,
                //应用id
                themeId: window[constant.ANALYSE_ID],
            },
            success: function (rs) {
                if (rs.success) {
                    //存在则下载文件
                    TempoUtils.download({
                        url: contextPath + "/api/ai/mine/sync/download-mleap-model",
                        data: {
                            //流程id
                            flowId: pid,
                        }
                    });
                } else {
                    //不存在则提示
                    TempoUtils.showTip(rs.message);
                }
            }
        });
    }

    /**
     * 下载MLeap管道公共包
     */
    var downloadMleapRuntime = function () {
        TempoUtils.downLoadFile({
            url: contextPath + "/api/ai/mine/sync/download-mleap-runtime-jar",
            data: {},
            method: 'get'
        });
    }

    /**
     * 点击下载MLeap文件下拉框
     * 下载MLeap文件
     * 下载管道公共包
     * @param ele
     * @constructor
     */
    var OpenMLeapSelectDialog = function (ele) {
        var target = $('#mleap-download');
        //长度大于0则将之前的菜单移除并重新初始化
        if (target.length > 0) {
            target.remove();
        }
        target = $("<ul style='z-index:999;' id='mleap-download'></ul>").appendTo($("body")).contextmenu({
            data: [{
                text: '下载Mleap文件',
                icon: "ui-icon tempo-ui-icon tempo-ui-icon-insight-downmleapfile_zip",
                id: 'download_mleap_file',
                //流程失败或者MLeap模型不存在则不能下载
                disabled: flowIsFailed || !mLeapModelIsExists
            }, {
                text: '下载管道公共包',
                icon: "ui-icon tempo-ui-icon tempo-ui-icon-insight-downcommomfile_jar",
                id: 'download_pl_common_file',
            }],
            select: function (e1, ui) {
                var selectedId = ui.select.id;
                /**
                 * 点击下载mleap模型文件
                 */
                if ("download_mleap_file" == selectedId) {
                    modelDownLoadLimitCheck();
                }
                /**
                 * 下载Mleap管道公共包
                 */
                if ("download_pl_common_file" == selectedId) {
                    downloadMleapRuntime();
                }
            }
        });
        var offset = $(ele.target).offset();
        if (flowIsFailed) {
            target.contextmenu("show", {position: {left: offset.left - 84, top: offset.top + 30, width: 130}});
        } else {
            target.contextmenu("show", {position: {left: offset.left - 60, top: offset.top + 30, width: 130}});
        }
    }

    //添加tab页
    var addTab = function (id, name, callback, nodeConfigId) {
        var tabs = $('#tempo-mine-viewing-resultshow');
        var lis = tabs.find('.ui-tabs-nav li');
        var li = tabs.find(".ui-tabs-nav li[aria-controls='" + id + "']");
        var index = lis.index(li);
        //如果已存在，则切换到该tab页,当重新点击节点时,不触发click方法
        if (index > -1) {
            tabs.tabs("option", "active", index);
            if (nodeConfigId && nodeTypeClickCache[nodeConfigId]) {
                var portName = nodeConfigId + "#" + nodeTypeClickCache[nodeConfigId];
                if (tabs.find("#" + id).find("span[name='" + portName + "']").length > 0 && (nodeConfigId == "missvalueprocess" || nodeConfigId == "writefile" || nodeConfigId == "writefilebatch")) {
                    tabs.find("#" + id).find("span[name='" + portName + "']").trigger("click");
                } else if (tabs.find("#" + id).find("span[name='" + portName + "']").length > 0) {
                    tabs.find("#" + id).find("span[name='" + portName + "']").trigger("click");
                } else {
                    if (nodeTypeClickCache[nodeConfigId].indexOf("model") > -1) {
                        tabs.find("#" + id).find("span[name^='" + nodeConfigId + "#model" + "']").trigger('click');
                    } else {
                        tabs.find("#" + id).find('.tempo-mine-viewing-result-style:first').trigger('click');
                    }
                }
            }
        } else {
            if (!name || !id) return;
            var tabTemplate = "<li><a href='#{href}'>#{label}</a> <span class='ui-icon tempo-ui-icon tempo-ui-icon-remove' role='presentation'>Remove Tab</span></li>";
            if (id == 'desc') {
                tabTemplate = "<li><a href='#{href}'>#{label}</a></li>";
            }
            var label = name,
                id = id,
                li = $(tabTemplate.replace(/#\{href\}/g, "#" + id).replace(/#\{label\}/g, label.replace(/</g, "&lt;")));


            tabs.find(".ui-tabs-nav").append(li);
            var descDiv = $("<div id='" + id + "'></div>");
            tabs.append(descDiv);
            callback(descDiv);
            tabs.tabs("refresh");
            tabs.tabs("option", "active", tabs.find(".ui-tabs-nav li").size() - 1);

            tabs.delegate("span.tempo-ui-icon-remove", "click", function () {
                var panelId = $(this).closest("li").remove().attr("aria-controls");
                var prevDom = tabs.find("#" + panelId).prev();
                tabs.find("#" + panelId).remove();
                tabs.tabs("refresh");
                if (prevDom.find(".tempo-mine-viewing-result-style").length > 0) {
                    prevDom.children(":first").children(":first").trigger("click");
                }
            });
        }
    }

    var selectHeader = function (target) {
        if (!$(target).hasClass('tempo-mine-viewing-result-style-sel')) {
            $(target).addClass('tempo-mine-viewing-result-style-sel');
        }
        $(target).siblings().removeClass('tempo-mine-viewing-result-style-sel');
    }


    var init = function () {
        initFlow();
        bindEvent();
    }

    //绘制流程图
    var loadInputdata = function (pid, board, callback, panel, result) {
        var pro = $("<div/>").tempoprogressbar();
        $.postForm({
            url: contextPath + getUrl('flowView', "/api/ai/mine/getObjectFlowInfoForView"),
            data: {
                flowId: pid,
                serviceid: pid,
                flowid: window.flowid,
                exeId: exeId,//可传可不传的参数
            },
            success: function (params) {
                flowIsFailed = params.failed;
                if (params && params.success && params.data) {
                    params = params.data;
                } else if (window.snapshotFlow && !$.isEmptyObject(window.snapshotFlow)) {
                    if (window.snapshotFlow.flow && !$.isEmptyObject(window.snapshotFlow.flow)) {
                        params = JSON.stringify(window.snapshotFlow.flow);
                    } else {
                        params = JSON.stringify(window.snapshotFlow);
                    }
                    //处理版本管理导出word页面执行成功的流程无法导出word的问题
                    if (!window.onlyShowFlow && window.snapshotFlow.status && window.snapshotFlow.status == "FINISHED") {
                        window.onlyShowFlow = false;
                    } else {
                        window.onlyShowFlow = true;
                    }
                }
                if (callback) callback(params.flowInfo ? params.flowInfo : params)
                if (exeId) {
                    renderBoard(params || {}, board, false, result.newFlowName, true, true);
                } else {
                    renderBoard(params || {}, board, false, result.newFlowName, true, false);
                }
                if (panel) {
                    panel.flowpanel('setNavigatorRoot')
                    panel.flowpanel('loaded');
                    if (window.onlyShowFlow) panel.find('.tempo-ui-icon-insight-msdoc').parent().hide();
                    //流程执行失败则禁用MLeap下载文件按钮
                    if (flowIsFailed || !mLeapModelIsExists) panel.find(".tempo-mine-board-headbar")
                        .find(".tempo-ui-icon-insight-downmleapfile").parent()
                        .attr("disabled", true)
                        .css({"opacity": "0.3", "pointer-events": "none"});
                }
            },
            complete: function () {
                pro.tempoprogressbar("close");
            },
            error: function () {

            }
        });
    }

    //初始化
    init();
}

window.MineViewlingController = MineViewlingController;